/**
 * @author:ruimin
 * @date:2016年10月25日
 * @description:
 */
var cols = new Array();
var colname = new Array();
var filterid=new Array();
var colid = "",colnamestr = "";
$(function () {   
	$("#functionNav").attr("href",navAddr);
  //获取藏品登记号查询条件
  getUserRight();
  var isZzgly = userInfo.roleid.indexOf("zongzhangguanliyuan")>-1;
  if(isZzgly){
	  $("#exportBtn_zdjh").show();
	  $("#exportBtn_lb").show();
	  $("#exportBtn_kf").show();
	  $("#exportBtn_zdy").show();
	  
	  $("#exptzzBtn_zdjh").show();
	  //$("#exptzzBtn_lb").show();
	  //$("#exptzzBtn_kf").show();
	  //$("#exptzzBtn_zdy").show();
	  
  }
  var params_zdjh =$("#form_zdjh").serializeObject();

  //初始化总账列表Table
  //去掉一开始的初始化表格，当加载自定义列时再加载表格数据
//  createTableOrderBy('#listtbl','antiques/zzquery.getZongZhangList.do','id',listtblColumns,params_zdjh);  
  
  //级联下拉框Id
  var doms_cpfl = ["DJH_CPFL1","DJH_CPFL2","DJH_CPFL3"];
  var doms_sd = ["DJH_SD1","DJH_SD2","DJH_SD3","DJH_SD4"];
  var doms_lb = ["LB_CPFL1","LB_CPFL2","LB_CPFL3"];
  var doms_kf = ["KF_CPFL1","KF_CPFL2","KF_CPFL3"];
//  var doms_zd = ["ZDLB1","ZDLB2","ZD1"];
  //设置藏品类别级联下拉框
  selectThree(url_cplb,doms_cpfl);
  //设置时代级联下拉框
  selectFour(url_nd,doms_sd);
  //设置藏品类别级联下拉框
  selectThree_lb(url_cplb,doms_lb);
  //设置藏品类别级联下拉框
  selectThree(url_cplb,doms_kf);
  
//获取并填充保管部门
  var bgbmJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_bgbm'});
  loadSelect("#BGBM",bgbmJson.rows,'id','name');

  //获取并填充藏品级别
  var cpjbJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_cpjb'});
  loadSelect("#DJH_CPJB",cpjbJson.rows,'id','name');
  
  //根据保管部门id获取并填充库房
  $("#BGBM").change(function(){
	  var bgbmid = $(this).val();
	  if(bgbmid !=null && bgbmid !=''){
		  var kfJson = ajaxResult("get",false,ProjectName+"/sysmanage.getkfIdNameBybgbmId.do",{'bgbmId':bgbmid});
		  loadSelect("#SZKF",kfJson.rows,'kfid','kfmc');
	  }
  });
	
  $(".imgtype").hide();
  
  //列表和图片切换
  $("#changeimg").click(function(){
	  var content = $("#changeimg")[0].src;
	  if(content.indexOf('imglist')>-1){
		  $(".listtype").hide();
		  $(".imgtype").show();
		  $("#changeimg").attr('src',"../../resources/images/recordlist.png"); 
		  $("#changeimg").attr('title',"列表显示"); 
	  }else{
		  $(".listtype").show();
		  $(".imgtype").hide();
		  $("#changeimg").attr('src',"../../resources/images/imglist.png"); 
		  $("#changeimg").attr('title',"图片显示"); 
	  }
	  var active_tabs = $(".nav-tabs .active a").attr("href");
	  switch (active_tabs){
	  case "#leiBie":
		  $("#queryBtn_lb").click();
		  break;
	  case "#kuFang":
		  $("#queryBtn_kf").click();
		  break;
	  case "#ziDing":
		  $("#queryBtn_zdy").click();
		  break;
	  default:
		  $("#queryBtn_zdjh").click();
	  }
  });
  
  //点击藏品登记查询-查询按钮
  $("#queryBtn_zdjh").click(function(){
	  showWaiting();
	  var params_zdjh = $("#form_zdjh").serializeObject();   
	  params_zdjh = $.extend(true, {"cols":colid}, params_zdjh);  
	  var content = $("#changeimg")[0].src;
	  if(content.indexOf('imglist')>-1){
		  refreshTable(params_zdjh);
	  }else{
		  showImgList(params_zdjh);
	  }

	  hideWaiting();
  });
//点击藏品登记查询-清除
  $("#clearBtn_zdjh").click(function(){
	  objInit($("#DJH_CPFL2"));
	  objInit($("#DJH_CPFL3"));
	  objInit($("#DJH_SD2"));
	  objInit($("#DJH_SD3"));
	  objInit($("#DJH_SD4"));
  });
  //点击藏品类别-查询按钮
  $("#queryBtn_lb").click(function(){
	  var params_lb = $("#form_lb").serializeObject(); 
	  params_lb = $.extend(true, {"cols":colid}, params_lb);  
	  var content = $("#changeimg")[0].src;
	  if(content.indexOf('imglist')>-1){
		  refreshTable(params_lb);
	  }else{
		  showImgList(params_lb);
	  }
  });
  //点击藏品库房-查询按钮
  $("#queryBtn_kf").click(function(){
	  var params_kf = $("#form_kf").serializeObject();
	  params_kf = $.extend(true, {"cols":colid}, params_kf);  
	  var content = $("#changeimg")[0].src;
	  if(content.indexOf('imglist')>-1){
		  refreshTable(params_kf);
	  }else{
		  showImgList(params_kf);
	  }
  });
  //点击藏品自定义-查询按钮
  $("#queryBtn_zdy").click(function(){
	  var params_zdy = $("#form_zdy").serializeObject();
	  params_zdy = $.extend(true, {"cols":colid}, params_zdy);  
	  var content = $("#changeimg")[0].src;
	  if(content.indexOf('imglist')>-1){
		  refreshTable(params_zdy);
	  }else{
		  showImgList(params_zdy);
	  }
  });
  
  initZdyFilter();
  initZdyCols();
  
  //显示自定义查询条件
  $("#setBtn_zdy").click(function(){
	  $('#zdysetModal').modal('show');
  });

  //保存自定义查询条件
  $("#zdyset_btn").click(function(){
	  fid = "";
	  $.each(filterid,function(index,value){
		  fid += value +',';
	  });
	  if(fid!="")
		  fid = fid.substr(0,fid.length-1);
	  ajaxResult("get",false,ProjectName+"/zzquery.saveZdyFilter.do",{"filter":fid,"userid":userInfo.userid});
	  $('#zdysetModal').modal('hide');
  });
  //打开自定义列
  $("#setBtn_zdycols").click(function(){
	  $('#zdycolsModal').modal('show');
  });

  //设置自定义列
  $("#zdycols_btn").click(function(){
	  colid = "";
	  $.each(cols,function(index,value){
		  colid += value +',';
	  });
	  colnamestr = "";
	  $.each(colname,function(index,value){
		  colnamestr += value +',';
	  });
	  if(colid!=""){
		  colid = colid.substr(0,colid.length-1);
		  colnamestr = colnamestr.substr(0,colnamestr.length-1);		  
	  }
	  ajaxResult("get",false,ProjectName+"/zzquery.saveZdyCols.do",{"cols":colid,"colnamestr":colnamestr,"userid":userInfo.userid});
	  setCols();
	  var params_zdy = $("#form_zdy").serializeObject();
	  refreshTable(params_zdy);
//	  params_zdy = $.extend(true, {"cols":colid}, params_zdy);  
//	  $('#listtbl').bootstrapTable('destroy');	
//	  createTableOrderBy('#listtbl','antiques/zzquery.getZongZhangList.do','id',listtblColumns,params_zdy);  
	  $('#zdycolsModal').modal('hide');
  });
  
  $("#exportBtn_zdjh").click(function(){
	  var params = $("#form_zdjh").serializeObject();
	  showexportmodal(params);
  });
  $("#exportBtn_lb").click(function(){
	  var params = $("#form_lb").serializeObject();
	  showexportmodal(params);
  });
  $("#exportBtn_kf").click(function(){
	  var params = $("#form_kf").serializeObject();
	  showexportmodal(params);
  });
  $("#exportBtn_zdy").click(function(){
	  var params = $("#form_zdy").serializeObject();
	  showexportmodal(params);
  });
  
  
  $("#exptzzBtn_zdjh").click(function(){
	  var params = $("#form_zdjh").serializeObject();
	  showexportmodal_zzb(params);
  });
  $("#exportBtn_lb").click(function(){
	  var params = $("#form_lb").serializeObject();
	  showexportmodal_zzb(params);
  });
  $("#exportBtn_kf").click(function(){
	  var params = $("#form_kf").serializeObject();
	  showexportmodal_zzb(params);
  });
  $("#exportBtn_zdy").click(function(){
	  var params = $("#form_zdy").serializeObject();
	  showexportmodal_zzb(params);
  });
})
function refreshTable(params){
	params = $.extend(true, {"cols":colid}, params);  
	$('#listtbl').bootstrapTable('destroy');	
	createTableOrderBy('#listtbl','antiques/zzquery.getZongZhangList.do','id',listtblColumns,params);  
}
function showexportmodal(params){
	  params = $.extend(true, {"cols":colid}, params);  
	  var r = ajaxResult("get",false,ProjectName+"/zzquery.getZongZhangList.do",params);
	  var total = r.total;
	  if(total==0){
		  alert("没有导出数据!");
		  return;
	  }
	  var pagesize = 1000;
	  var html = "";
	  var pagetotal = total %pagesize ==0?total/pagesize:(parseInt(total/pagesize)+1);
	  for(var i=0;i<pagetotal;i++){		  
		  if(i==(pagetotal-1)){
			  html += "<a herf='#'  onclick='exportList("+pagesize*i+","+pagesize+")'>导出第"+(pagesize*i+1)+"-"+total+"条数据</a><br/>";
		  }else
			  html += "<a herf='#'  onclick='exportList("+pagesize*i+","+pagesize+")'>导出第"+(pagesize*i+1)+"-"+pagesize*(i+1)+"条数据</a><br/>";
	  }
	  $("#div_export").html(html);
	  $('#exportModal').modal('show');
  }

function showexportmodal_zzb(params){
	  params = $.extend(true, {"cols":colid}, params);  
	  var r = ajaxResult("get",false,ProjectName+"/zzquery.getZongZhangCount_zzb.do",params);
	  var zrcount =0;
	  var lscount = 0;
	  if(r.status=="ok"){
		  zrcount = r.data.zr;
		  lscount = r.data.ls;
	  }
	  if(zrcount==0&&lscount==0){
		  alert("没有导出数据!");
		  return;
	  }
	  var pagesize = 1000;
	  var html = "";
	  var lspagetotal = lscount %pagesize ==0?lscount/pagesize:(parseInt(lscount/pagesize)+1);
	  for(var i=0;i<lspagetotal;i++){		  
		  if(i==(lspagetotal-1)){
			  html += "<a herf='#'  onclick='exportList_zzb("+pagesize*i+","+pagesize+",1)'>导出历史总账第"+(pagesize*i+1)+"-"+lscount+"条数据</a><br/>";
		  }else
			  html += "<a herf='#'  onclick='exportList_zzb("+pagesize*i+","+pagesize+",1)'>导出历史总账第"+(pagesize*i+1)+"-"+pagesize*(i+1)+"条数据</a><br/>";
	  }
	  var zrpagetotal = zrcount %pagesize ==0?zrcount/pagesize:(parseInt(zrcount/pagesize)+1);
	  for(var i=0;i<zrpagetotal;i++){		  
		  if(i==(zrpagetotal-1)){
			  html += "<a herf='#'  onclick='exportList_zzb("+pagesize*i+","+pagesize+",2)'>导出自然总账第"+(pagesize*i+1)+"-"+zrcount+"条数据</a><br/>";
		  }else
			  html += "<a herf='#'  onclick='exportList_zzb("+pagesize*i+","+pagesize+",2)'>导出自然总账第"+(pagesize*i+1)+"-"+pagesize*(i+1)+"条数据</a><br/>";
	  }
	  $("#div_export_zzb").html(html);
	  $('#exportModal_zzb').modal('show');
  }
function exportList(export_offset,export_limit){
	var form=$('#form_zdjh'); //得到form对象
	var active_tabs = $(".nav-tabs .active a").attr("href");
	switch (active_tabs){
	case "#leiBie":
		form=$('#form_lb');
		break;
	case "#kuFang":
		form=$('#form_kf');
		break;
	case "#ziDing":
		form=$('#form_zdy');
		break;
	default:
		form=$('#form_zdjh');
	}
	var offset=$("<input type='hidden' name='export_offset'/>");
	offset.attr("value", export_offset+"");
	form.append(offset);
	var limit=$("<input type='hidden' name='export_limit'/>");
	limit.attr("value", export_limit+"");
	form.append(limit);
	form.attr("action", ProjectName+"/zzquery.exportExcelCpList.do");
	form.submit();
	limit.remove();
	offset.remove();
}
function exportList_zzb(export_offset,export_limit,typenum){
	var form=$('#form_zdjh'); //得到form对象
	var active_tabs = $(".nav-tabs .active a").attr("href");
	switch (active_tabs){
	case "#leiBie":
		form=$('#form_lb');
		break;
	case "#kuFang":
		form=$('#form_kf');
		break;
	case "#ziDing":
		form=$('#form_zdy');
		break;
	default:
		form=$('#form_zdjh');
	}
	var offset=$("<input type='hidden' name='export_offset'/>");
	offset.attr("value", export_offset+"");
	form.append(offset);
	var limit=$("<input type='hidden' name='export_limit'/>");
	limit.attr("value", export_limit+"");
	form.append(limit);
	var type=$("<input type='hidden' name='type'/>");
	type.attr("value", typenum);
	form.append(type);
	form.attr("action", ProjectName+"/zzquery.exportExcelCpList_zzb.do");
	form.submit();
	limit.remove();
	offset.remove();
	type.remove();
}
/**
 * 初始化自定义列
 */
  function initZdyCols(){
	  result = ajaxResult("get",false,'zongZhangZdycols.json',"");
	  var r2 = ajaxResult("get",false,ProjectName+"/zzquery.getZdyColsByUserid.do",{"userid":userInfo.userid});
	  if(r2.status=="ok"){
		  colid = r2.colid;
		  colnamestr = r2.colname;
		  if(colid!=null&&colid!=""){
			  var colnamestr_arr = colnamestr.split(",");
			  var i=0;
			  $.each(colid.split(","),function(index,value){
				  cols.push(value); 
				  colname.push(colnamestr_arr[i]);
				  i++;
			  });
		  }
	  }
	  var zdyhtml="";
	  for(var i=0;i<result.length;i++){
		  var obj = result[i];
		  var f=false;
		  $.each(colid.split(","),function(index,value){
				 if(obj.id==value)
					 f=true;
		  });
		  if(f){
			  zdyhtml+='<input name="cb_zdycols" type="checkbox" checked value="'+obj.id+'" onchange="chg_zdycols(this,\''+obj.id+'\',\''+obj.name+'\')"/><label>'+obj.name+'</label><br/>';
		  }else{
			  zdyhtml+='<input name="cb_zdycols" type="checkbox" value="'+obj.id+'" onchange="chg_zdycols(this,\''+obj.id+'\',\''+obj.name+'\')"/><label>'+obj.name+'</label><br/>';
		  }
	  }
	  $("#div_zdycols").html(zdyhtml);
	  if(colid!=null&&colid!=""){		  
		  setCols();	  
	  }
	  var params_zdjh = $("#form_zdjh").serializeObject();
	  params_zdjh = $.extend(true, {"cols":colid}, params_zdjh);  
	  $('#listtbl').bootstrapTable('destroy');	
	  var r2 = ajaxResult("get",false,"antiques/zzquery.getZongZhangList.do",params_zdjh);
	  createTableOrderBy('#listtbl','antiques/zzquery.getZongZhangList.do','id',listtblColumns,params_zdjh);  
  }
/**
 * 初始化自定义查询条件
 */
function initZdyFilter(){
	  result = ajaxResult("get",false,'zongZhangZdy.json',"");
	  var r2 = ajaxResult("get",false,ProjectName+"/zzquery.getZdyFilterByUserid.do",{"userid":userInfo.userid});
	  var fid = "";
	  if(r2.status=="ok"){
		  var fid = r2.filter;
		  if(fid!=null&&fid!=""){
			  $.each(fid.split(","),function(index,value){
				  filterid.push(value); 
			  });
		  }
	  }
	  var zdyhtml="";
	  for(var i=0;i<result.length;i++){
		  var obj = result[i];
		  var f=false;
		  $.each(filterid,function(index,value){
				 if(obj.id==value)
					 f=true;
		  });
		  if(f){
			  zdyhtml+='<input name="cb_zdyset" checked type="checkbox" value="'+obj.id+'" onchange="chg_zdyset(this,\''+obj.id+'\',\''+obj.name+'\',\''+obj.type+'\',\''+obj.tablename+'\')"/><label>'+obj.name+'</label><br/>';
			  showfilter(obj.id,obj.name,obj.type,obj.tablename);
		  }
		  else
			  zdyhtml+='<input name="cb_zdyset" type="checkbox" value="'+obj.id+'" onchange="chg_zdyset(this,\''+obj.id+'\',\''+obj.name+'\',\''+obj.type+'\',\''+obj.tablename+'\')"/><label>'+obj.name+'</label><br/>';
	  }
	  $("#div_zdyset").html(zdyhtml);
}
  function chg_zdyset(o,id,name,type,tablename){
	var groupid = "div-group-"+id;
	  if(o.checked==true){
		  showfilter(id,name,type,tablename)
		  filterid.push(id);
	  }else{
		  filterid.splice($.inArray(id, filterid), 1);
		  $("#"+groupid).remove();
	  }
  }
/**
 * 显示自定义查询条件
 * @param id
 * @param name
 * @param type
 * @param tablename
 */
function showfilter(id,name,type,tablename){
	var groupid = "div-group-"+id;
	var div_filter = '<div class="form-group" id="'+groupid+'"><label for="'+id+'">'+name+'：</label>';
	if(type=="input"){			  
		div_filter +='<input type="text" class="form-control" id="ZDY_'+id+'" name="'+id+'" placeholder="">';
		div_filter += '</div>';
		$("#div_zdyqueryfilter").append(div_filter);
	}else if(type.indexOf("select")>-1){
		var sl = type.split("_")[1];
		if(sl==1){
			div_filter += '<select class="form-control" id="ZDY_'+id+'" name="'+id+'" style="width: 25%;">'+
			'</select>'+
			'<span>';
		}else
			for(var i=0;i<sl;i++){
				div_filter += '<select class="form-control" id="ZDY_'+id+(i+1)+'" name="'+id+(i+1)+'" style="width: 70px">'+
				'</select>'+
				'<span>';
			}
		div_filter += '</div>';
		$("#div_zdyqueryfilter").append(div_filter);
		if(sl==1){
			ajaxFunc("get",true,'antiques/sysmanage.getIdAndNameInJb.do?tableName='+tablename,"",getSelectOptions,"ZDY_"+id);  
		}else{				  
			var doms_zdy;
			var url_zdy = "antiques/sysmanage.getIdNameParentid.do?tableName="+tablename;
			if(sl==3){
				doms_zdy = ["ZDY_"+id+'1',"ZDY_"+id+'2',"ZDY_"+id+'3'];	
				selectThree(url_zdy,doms_zdy);				  
			}else  if(sl==4){
				doms_zdy = ["ZDY_"+id+'1',"ZDY_"+id+'2',"ZDY_"+id+'3',"ZDY_"+id+'4'];
				selectFour(url_zdy,doms_zdy);	
			}
		}
	}else if(type=="szkf"){
		div_filter +='<select class="form-control" id="ZDY_BGBM" name="BGBM" style="width: 80px">'+
		'</select>'+
		'<select class="form-control" id="ZDY_SZKF" name="SZKF"  style="width: 80px;">'+
		'</select>';
		div_filter += '</div>';
		$("#div_zdyqueryfilter").append(div_filter);
		
		var bgbmJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_bgbm'});
		loadSelect("#ZDY_BGBM",bgbmJson.rows,'id','name');
		//根据保管部门id获取并填充库房
		$("#ZDY_BGBM").change(function(){
			var bgbmid = $(this).val();
			if(bgbmid !=null && bgbmid !=''){
				var kfJson = ajaxResult("get",false,ProjectName+"/sysmanage.getkfIdNameBybgbmId.do",{'bgbmId':bgbmid});
				loadSelect("#ZDY_SZKF",kfJson.rows,'kfid','kfmc');
			}
		});
	}
  }

function chg_zdycols(o,id,name){
	  if(o.checked==true){
		  cols.push(id);
		  colname.push(name);
	  }else{
		  cols.splice($.inArray(id, cols), 1);
		  colname.splice($.inArray(name, colname), 1);
	  }
}
//总账列表table表头
var listtblColumns=[ {
    field: 'zdjh',
    title: '总登记号',
    sortable:true
  }, {
    field: 'flh',
    title: '分类号',
    sortable:true
  }, {
    field: 'cpmc',
    title: '名称',
    sortable:true,
    formatter: function(value, row, index) {
  	  return '<a href="javascript:void(0)" onclick="detailWin(\''+row.zdjh+'\',this)">'+value+'</a>';
  	  //return '<a href="zongZhangDetail.html?zdjh='+row.ZDJH+'">'+value+'</a>';
  	}
  }, {
    field: 'cpfl',
    title: '藏品分类',
    sortable:false,
    formatter: function(value, row, index){
    	if(row.cpfl3!="")
    		return row.cpfl3;
    	else if( row.cpfl2!="")
    		return row.cpfl2;
    	else
    		return row.cpfl1;
    }
  }, {
    field: 'sjsl',
    title: '实际数量',
    sortable:true,
    formatter: function(value, row, index){
    	return row.sjsl;
    }
  },  {
	    field: 'sjsldw',
	    title: '实际数量单位',
	    sortable:true,
	    formatter: function(value, row, index){
	    	return row.sjsldw;
	    }
	  }, {
    field: 'lyms',
    title: '来源',
    sortable:true
  }];

function showImgList(params){
	var result = createImgTable("get", false, "antiques/zzquery.getZongZhangImgList.do", params,creatImgList,"#page",1);
}
//生成图片列表
function creatImgList(data){
	var tHtml = "";
	if(data != null){
		$.each(data,function(index,value){
			var imgsrc = "../../resources/images/sun.jpg";
			if(value.sldz!=undefined&&value.sldz!=""){
				imgsrc=imageAddr+value.sldz;
			}
			tHtml += "<div>";
			tHtml += "<a href='#' onclick='detailWin(\""+value.zdjh+"\")'><img src='"+imgsrc+"'></a>";
			tHtml += "<p><a href='#' onclick='detailWin(\""+value.zdjh+"\",this)'>"+value.cpmc+"</a></p>";
			tHtml += "</div>";
		});
	}
	$(".imglist").html(tHtml);
}

//打开藏品详细对话框
function detailWin(zdjh,ele){
	var bgs = $('.bgRed');
	$.each(bgs,function() {
	    $(this).removeClass("bgRed");
	});
	$(ele).parent().parent().children("td").toggleClass("bgRed");
	$("#detailModal").modal("show");
    if(userInfo.roleid=="cangpinchaxunyuan"){
      $("#cpDetailframe").attr("height",400);
    }
    $("#cpDetailframe").attr("src","zongZhangDetail.html?zdjh="+zdjh);
	$("#detailModal").attr("zdjh",zdjh);
}

function setCols(){
	listtblColumns = new Array();
	listtblColumns.push({
	    field: 'zdjh',
	    title: '总登记号',
        sortable:true
	  });
	listtblColumns.push({
	    field: 'flh',
	    title: '分类号',
        sortable:true
	  });
	listtblColumns.push( {
	    field: 'cpmc',
	    title: '名称',
        sortable:true,
	    formatter: function(value, row, index) {
	      var a = '<a onclick="detailWin(\''+row.zdjh+'\',this)">'+value+'</a>';
	  	  return a;
	  	}
	  });
	for(var i=0;i<cols.length;i++){
		if(cols[i]=="cpfl"){
			listtblColumns.push({
			    field: cols[i],
			    title: colname[i],
		        sortable:false,
			    formatter: function(value, row, index){
			    	if(row.cpfl3!="")
			    		return row.cpfl3;
			    	else if( row.cpfl2!="")
			    		return row.cpfl2;
			    	else
			    		return row.cpfl1;
			    }
			  });
		}else if(cols[i]=="sd"){
			listtblColumns.push({
			    field: cols[i],
			    title: colname[i],
		        sortable:false,
			    formatter: function(value, row, index){
			    	if(row.sdms!="")
			    		return row.sdms;
			    	else if( row.sd4!="")
			    		return row.sd4;
			    	else if( row.sd3!="")
			    		return row.sd3;
			    	else if( row.sd2!="")
			    		return row.sd2;
			    	else
			    		return row.sd1;
			    }
			  });
		}else if(cols[i]=="zd"){
			listtblColumns.push({
			    field: cols[i],
			    title: colname[i],
		        sortable:false,
			    formatter: function(value, row, index){
			    	if(row.zdms!="")
			    		return row.zdms;
			    	else if( row.zd1!="")
			    		return row.zd1;
			    	else if( row.zdlb2!="")
			    		return row.zdlb2;
			    	else
			    		return row.zdlb1;
			    }
			  });
		}else{
			listtblColumns.push({
				field: cols[i],
				title: colname[i],
		        sortable:true
			});
		}
	}
}
